package com.semp.gu.connector;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.semp.gu.domain.Album;
import com.semp.gu.domain.local.LocalAlbum;
import com.semp.gu.domain.local.LocalAlbumElement;
import com.semp.gu.domain.remote.RemoteAlbum;
import com.semp.gu.domain.remote.RemoteGallery;

public class ConnectorMock implements IConnector {

	private RemoteGallery		remoteGallery;
	private final static Logger	logger	= LoggerFactory.getLogger(ConnectorMock.class);

	public ConnectorMock() {
		remoteGallery = new RemoteGallery();
		remoteGallery.setName("Pipo Gallery");

		RemoteAlbum album1 = new RemoteAlbum();
		album1.setName("Album 1");

		RemoteAlbum album2 = new RemoteAlbum();
		album2.setName("Album 2");
		RemoteAlbum album21 = new RemoteAlbum();
		album21.setName("Album 21");
		RemoteAlbum album22 = new RemoteAlbum();
		album22.setName("Album 22");
		List<Album> subAlbums2 = new ArrayList<Album>();
		subAlbums2.add(album21);
		subAlbums2.add(album22);
		album2.setSubAlbums(subAlbums2);

		List<Album> subAlbums = new ArrayList<Album>();
		subAlbums.add(album1);
		subAlbums.add(album2);
		remoteGallery.setAlbums(subAlbums);
	}

	public void createAlbum(RemoteAlbum newAlbum, RemoteAlbum mainAlbum) {
		newAlbum.setParent(mainAlbum);
		mainAlbum.getSubAlbums().add(newAlbum);
	}

	public RemoteGallery getGallery() {
		return remoteGallery;
	}

	public void uploadFiles(LocalAlbum localAlbum, RemoteAlbum remoteAlbum) {
		List<LocalAlbumElement> albumElements = localAlbum.getElements();
		for (LocalAlbumElement localAlbumElement : albumElements) {
			logger.info("Mock: uploading file {}", localAlbumElement.getName());
		}
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public void uploadFile(LocalAlbumElement localAlbumElement, RemoteAlbum remoteAlbum) throws IOException {
		List<File> convertedFileList = localAlbumElement.getConvertedFileList();
		for (File convertedFile : convertedFileList) {
			logger.info("Mock: uploading file {}", convertedFile);
		}
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
